package com.tuanda.app.customviewdemo.cavans;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by LiDongduo on 2018/9/20.
 */
public class DrawPieView extends View {

    private Paint mPaint;

    public DrawPieView(Context context) {
        this(context,null);
    }

    public DrawPieView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DrawPieView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        RectF rectF = new RectF(60,60,160,160);
        RectF rectF1 = new RectF(56,56,156,156);
        mPaint.setColor(Color.parseColor("#a020a8"));
        canvas.drawArc(rectF,0,10, true,mPaint);
        mPaint.setColor(Color.parseColor("#9b9ea3"));
        canvas.drawArc(rectF,12,8,true,mPaint);
        mPaint.setColor(Color.GREEN);
        canvas.drawArc(rectF,22,45,true,mPaint);
        mPaint.setColor(Color.BLUE);
        canvas.drawArc(rectF,68,100,true,mPaint);
        mPaint.setColor(Color.RED);
        canvas.drawArc(rectF1,-180,140,true,mPaint);
        mPaint.setColor(Color.YELLOW);
        canvas.drawArc(rectF,-40,38,true,mPaint);
    }
}
